package cn.wanda.bi.sunshine.platform.server.client.wrapper;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import cn.wanda.bi.sunshine.platform.server.client.FFanClient;
import cn.wanda.bi.sunshine.platform.server.controller.response.common.SimpleResponse;
import cn.wanda.bi.sunshine.platform.server.utils.JsonUtil;
import cn.wanda.bi.sunshine.platform.server.utils.exception.ClientException;


/**
 * Created by wangfupeng1
 */
@Component
public class LoginWrapper {
    public static final Logger logger = LoggerFactory.getLogger(LoginWrapper.class);

    @Value("${client.ffan.user_register.appid:}")
    private String ffan_appid;
    @Value("${client.ffan.user_register.type:}")
    private Integer ffan_type;
    @Value("${client.ffan.user_register.channel:}")
    private Integer ffan_channel;
    @Value("${client.ffan.user_register.activityId:}")
    private Integer ffan_activity_id;

    @Autowired
    private FFanClient ffanClient;

    /**
     * 发送短信验证码
     */
    public SimpleResponse sendVerifyCode(String mobile, String source) {
        SimpleResponse response =
                JsonUtil.toObject(ffanClient.sendSMSCode(mobile, ffan_appid, ffan_type), SimpleResponse.class);
        if (response.getStatus() != 200)
            throw new ClientException(response.getStatus(), response.getMessage());
        return response;
    }

    /**
     * 校验验证码
     */
    public SimpleResponse checkVerifyCode(String mobile, String verifyCode, Integer source) {
        SimpleResponse response =
                JsonUtil.toObject(ffanClient.checkVerifyCode(mobile, ffan_type, verifyCode, ffan_appid), SimpleResponse.class);
        if (response.getStatus() != 200)
            throw new ClientException(response.getStatus(), response.getMessage());
        return response;
    }

}
